//
//  BCWalletDetailNormalTagCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/12.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCWalletDetailNormalTagCell.h"

@implementation BCWalletDetailNormalTagCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.tagLabel = [QMUILabel new];
    self.tagLabel.textColor = [UIColor qmui_colorWithHexString:@"#666666"];
    self.tagLabel.font = [UIFont systemFontOfSize:9 weight:UIFontWeightRegular];
    self.tagLabel.numberOfLines = 0;
    self.tagLabel.contentEdgeInsets = UIEdgeInsetsMake(2, 8, 2, 8);
    [self.contentView addSubview:self.tagLabel];
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(5.0);
        make.top.mas_equalTo(self.titleLabel.mas_top).offset(self.titleLabel.font.lineHeight/2-self.tagLabel.font.lineHeight/2-self.tagLabel.contentEdgeInsets.top);
        make.width.mas_lessThanOrEqualTo(ScreenWidth/2-BCWalletDetailCellContentLeftPadding-5.0);
    }];
    self.tagLabel.layer.cornerRadius = 2;
    self.tagLabel.layer.borderColor = [UIColor qmui_colorWithHexString:@"#C2C2C2"].CGColor;
    self.tagLabel.layer.borderWidth = 1.0;
    
    //
//    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.contentView).offset(BCWalletDetailCellContentLeftPadding);
//        make.top.mas_equalTo(self.contentView).offset(BCWalletDetailCellContentTopPadding);
//        make.width.mas_lessThanOrEqualTo(self.contentView).offset(-2*BCWalletDetailCellContentLeftPadding);
//    }];
}


- (void)setCellData:(UserWalletDetailsDataModel *)cellData {
    self.tagLabel.text = cellData.tag;
    //
    CGSize tagSize = [self.tagLabel sizeThatFits:CGSizeMake(ScreenWidth/2-BCWalletDetailCellContentLeftPadding-5.0, CGFLOAT_MAX)];
    //
    CGFloat tagWidth = tagSize.width;
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_lessThanOrEqualTo(self.contentView).offset(-2*BCWalletDetailCellContentLeftPadding-tagWidth-5.0);
    }];
    [self layoutIfNeeded];
    //
    [super setCellData:cellData];
}


/**
 重写该方法
 */
- (CGSize)titieFitsSize:(CGSize)size {
    CGSize superSize = [super titieFitsSize:size];
    CGFloat tagWidth = CGRectGetWidth(self.tagLabel.frame);
    CGFloat width = superSize.width-tagWidth-5.0;
    return CGSizeMake(width, superSize.height);
}

@end
